package com.hfzy.ihk.facade.linkcall.entity.flow.config;


import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hfzy.ihk.common.facade.BaseEntity;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.util.Date;
import java.util.List;

/***
 * 自定义的用户回答分支
 * （自定义分支）
 *
 *  附加
 *
 *   YES("y", "肯定"),
     NO("n", "否定"),
     REJECT("r", "拒绝"),
     UNKNOWN("u", "未识别");

    此时 flowId,flowStepId为0，表示公用的分支
    flowId 有值且不为0时，flowStepId 为0  表示为 id 为 flowId 流程的默认分支
 * */
@Document(indexName = "#{elasticSearchConfig.indexName()}_customer_answer_way",shards = 24,replicas = 2, type = "data")
public class CustomerAnswerWay implements BaseEntity {
    @Id
    @Field(type = FieldType.Keyword)
    private String id;

    private long version;

    /**分支名称*/
    private String name;

    /**属于哪个话术流程*/
    @Field(type = FieldType.Keyword)
    private String flowId;

    /**属于哪个流程步骤*/
    @Field(type = FieldType.Keyword)
    private String flowStepId;

    /**关键词*/
    private List<String> keyworlds;

    /**答法*/
    @Field(type = FieldType.Text)
    private List<String> content;

    /**该分支的key值  默认系统生成 "custom_"+id 构建*/
    @Field(type = FieldType.Keyword)
    private String typeKey;

    private long createUserId;

    @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss" )
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @JSONField(format="yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @Field(type = FieldType.Date, format = DateFormat.custom, pattern = "yyyy-MM-dd HH:mm:ss" )
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    @JSONField(format="yyyy-MM-dd HH:mm:ss")
    private Date modTime;


    @Override
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getFlowId() {
        return flowId;
    }

    public void setFlowId(String flowId) {
        this.flowId = flowId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<String> getKeyworlds() {
        return keyworlds;
    }

    public void setKeyworlds(List<String> keyworlds) {
        this.keyworlds = keyworlds;
    }

    public String getTypeKey() {
        return typeKey;
    }

    public void setTypeKey(String typeKey) {
        this.typeKey = typeKey;
    }

    public long getCreateUserId() {
        return createUserId;
    }

    public void setCreateUserId(long createUserId) {
        this.createUserId = createUserId;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getModTime() {
        return modTime;
    }

    public void setModTime(Date modTime) {
        this.modTime = modTime;
    }

    public String getFlowStepId() {
        return flowStepId;
    }

    public void setFlowStepId(String flowStepId) {
        this.flowStepId = flowStepId;
    }

    public List<String> getContent() {
        return content;
    }

    public void setContent(List<String> content) {
        this.content = content;
    }

    @JsonIgnore
    public String getKeyworldsStr(){
        String keyWorldStr = "";
        if(this.keyworlds!=null && !this.keyworlds.isEmpty()){
            for(String str:this.keyworlds){
                keyWorldStr += str+",";
            }
        }
        if(keyWorldStr.lastIndexOf(",")!=-1){
            keyWorldStr = keyWorldStr.substring(0,keyWorldStr.lastIndexOf(","));
        }
        return  keyWorldStr;
    }
    @JsonIgnore
    public String getContentStr(){
        String contentStr = "";
        if(this.content!=null && !this.content.isEmpty()){
            for(String str:this.content){
                contentStr += str+",";
            }
        }
        if(contentStr.lastIndexOf(",")!=-1){
            contentStr = contentStr.substring(0,contentStr.lastIndexOf(","));
        }
        return  contentStr;
    }

    public long getVersion() {
        return version;
    }

    public void setVersion(long version) {
        this.version = version;
    }
}
